﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class ActorInfo 
{
    public int id { get;  set; }
    public string name { get;  set; }
    public int hp { get;  set; }
    public int maxHp { get;  set; }
    public float moveSpeed { get;  set; }
    public int attack { get;  set; }
    [NonSerialized]
    public Action<int, int> onHpChange;
    public ActorInfo(int id,string name,int hp,float moveSpeed,int attack)
    {
        this.id = id;
        this.name = name;
        this.hp = hp;
        this.maxHp = hp;
        this.moveSpeed = moveSpeed;
        this.attack = attack;

    }

    /// <summary>
    /// 掉血
    /// </summary>
    /// <param name="count"></param>
    public void TakeHp(int count)
    {
        int oldhp = hp;
        hp -= count;
        hp = Mathf.Max(0, hp);
        if (oldhp != hp)
        {
            if (onHpChange!=null)
            {
                onHpChange(oldhp, hp);
            }
            
        }
    }
    /// <summary>
    /// 恢复血
    /// </summary>
    /// <param name="count"></param>
    public void RestoreHp(int count)
    {
        int oldhp = hp;
        hp += count;
        hp = Mathf.Min(maxHp, hp);
        if (oldhp != hp)
        {
            if (onHpChange!=null)
            {
                onHpChange(oldhp, hp);
            }
           
        }
    }
}
